package com.youxin.cpcenter.service.impl;

import org.springframework.stereotype.Service;
import com.youxin.busfoundation.bean.ResponseObject;
import com.youxin.busfoundation.bean.email.RequestEmailBean;
import com.youxin.busfoundation.email.EmailController;
import com.youxin.cpcenter.config.EmailBeanConfig;
import com.youxin.cpcenter.controller.LoginController;
import com.youxin.cpcenter.service.EmailService;

@Service("emailService")
public class EmailServiceImpl implements EmailService{
	protected static org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(LoginController.class);

	public ResponseObject sendEmail(RequestEmailBean bean)
	{
		EmailBeanConfig emailBeanConfig=EmailBeanConfig.getConfig();
		emailBeanConfig.setTo(bean.getTo());
		EmailController emailController=new EmailController(emailBeanConfig);
		String content=getContent(bean);
		try {
			emailController.sendMessage("商理事消息", content,true);
			return ResponseObject.successObject();
		} catch (Exception e) {
			logger.error("接口发送邮件异常", e);
			return ResponseObject.userFailure("邮件发送信息");
		}
	}
	
	private String getContent(RequestEmailBean message)
	{
		String content="<!DOCTYPE html>\n" +
                "<html lang=\"en\">\n" +
                "<head>\n" +
                "  <meta charset=\"UTF-8\">\n" +
                "  <title>商理事消息</title>\n" +
                "  <style rel=\"stylesheet\" type=\"text/css\">\n" +
                "    body,html,p,div,span,img { margin: 0;padding: 0;font-size: 14px;color: #333;font-family: -apple-system,PingFang SC,Hiragino Sans GB,Arial,Microsoft YaHei,Helvetica Neue,sans-serif;}\n" +
                "    a {color: #4a90e2;font-size: 14px;text-decoration: none}\n" +
                "    body {background: #eceef3;}\n" +
                "    .forward-wrapper {width: 560px;margin: 100px auto;padding-left: 50px;box-sizing: border-box;background: #fff;border: 1px solid #e1e8ef;}\n" +
                "    .logo {padding: 60px 0 36px 0;}\n" +
                "    .logo img {width: 151px;height: 38px;}\n" +
                "    .msg-wrapper {width: 462px;padding-bottom: 30px;border-bottom: 1px solid #d8d8d8;}\n" +
                "    .header {height: 16px;line-height: 16px;}\n" +
                "    .info {padding-top: 8px;}\n" +
                "    .company, .short-name {color: #4a90e2;}\n" +
                "    .company {padding-right: 2px;}\n" +
                "    .border {padding: 0 10px;font-size: 15px;}\n" +
                "    .tips {width: 460px;height: 16px;line-height: 16px;padding: 10px 0 15px;}\n" +
                "    .content {width: 460px;padding: 15px;border: 1px solid #d8d8d8;line-height: 21px;box-sizing: border-box;}\n" +
                "    .msg-wrapper .tip {height: 14px;line-height: 14px;padding-top: 15px;}\n" +
                "    .tip a {text-decoration: underline;}\n" +
                "    .contact-wrapper {width: 462px;padding: 20px 0;border-bottom: 1px solid #d8d8d8;}\n" +
                "    .line {height: 20px;line-height: 20px;}\n" +
                "    .contact {display: flex;display: -ms-flexbox;padding: 10px 0;overflow: hidden;}\n" +
                "    .contact > div {float: left;}\n" +
                "    .contact-group.first {padding-right: 60px;}\n" +
                "    .contact-group span {font-size: 14px;}\n" +
                "    .contact-group a {color: #333;text-decoration: underline;}\n" +
                "    .footer {padding: 20px 0 54px 0;}\n" +
                "    .footer .tip {height: 18px;line-height: 18px;padding-bottom: 22px;}\n" +
                "    .saoma-wrapper {display: flex;display: -ms-flexbox;overflow: hidden;}\n" +
                "    .saoma-wrapper > div {float: left;text-align: center;}\n" +
                "    .ma {width: 118px;display: flex;display: -ms-flexbox;flex-direction: column;align-items: center;padding-right: 13px;}\n" +
                "    .ma img {width: 116px;height: 116px;border: 1px solid #d8d8d8;}\n" +
                "    .name {line-height: 18px;padding-top: 10px;}\n" +
                "    .line a {text-decoration: underline}\n" +
                "  </style>\n" +
                "</head>\n" +
                "<body>\n" +
                "  <div class=\"forward-wrapper\">\n" +
                "    <div class=\"logo\"><img src=\"http://7xvx8c.com1.z0.glb.clouddn.com/sls-logo-font.png\" alt=\"logo\"></div>\n" +
                "    <div class=\"content-wrapper\">\n" +
                "      <div class=\"msg-wrapper\">\n" +
                "     <div class=\"header\">您好，我是:param0</div>\n" +
                "        <div class=\"header info\">\n" +
                "          <a  class=\"company\" target=\"_blank\" href=\" \">:param2</a > <a class=\"short-name\" target=\"_blank\" href=\"http://www.slsai.com/app/#/company-detail?uid=:param1\">:param3</a ><span class=\"border\">|</span><span class=\"position\">:param4</span>\n" +
                "        </div>\n" +
                "        <div class=\"tips\">想跟您取得如下合作：</div>\n" +
                "        <div class=\"content\">:param6</div>\n" +
                "        <div class=\"tip\">如您感兴趣，请通过  <a href=\"mailto::param5\">:param5</a >  联系我。</div>\n" +
                "      </div>\n" +
                "      <div class=\"contact-wrapper\">\n" +
                "        <div class=\"title line\">本邮件由平台转发，暂不支持直接回复！如有任何疑问，请联系我们：</div>\n" +
                "        <div class=\"contact\">\n" +
                "          <div class=\"contact-group line first\">客服热线：<span>400-806-2262</span></div>\n" +
                "          <div class=\"contact-group line\">客服邮箱：<a href=\"mailto:product@slashedon.com\">product@slashedon.com</a ></div>\n" +
                "        </div>\n" +
                "        <div class=\"websit line\">\n" +
                "          商理事官网：<a target=\"_blank\" href=\"http://www.slsai.com\">http://www.slsai.com<a>\n" +
                "        </div>\n" +
                "      </div> \n" +
                "    </div>\n" +
                "    <div class=\"footer\">\n" +
                "      <div class=\"tip\">您也可以通过商理事官方微信公众号联系到我们：</div>\n" +
                "      <div class=\"saoma-wrapper\">\n" +
                "        <div class=\"ma\">\n" +
                "          <img src=\"http://7xvx8c.com1.z0.glb.clouddn.com/sls-qrcode-1.jpg\" alt=\"服务号\">\n" +
                "          <p class=\"name\">服务号</p >\n" +
                "        </div>\n" +
                "        <div class=\"ma\">\n" +
                "          <img src=\"http://7xvx8c.com1.z0.glb.clouddn.com/sls-qrcode-2.jpg\" alt=\"订阅号\">\n" +
                "          <p class=\"name\">订阅号</p >\n" +
                "        </div>\n" +
                "      </div>\n" +
                "    </div>\n" +
                "  </div>\n" +
                "</body>\n" +
                "</html>";
		
		return content;
	}
}
